package com.legoo.studaychineseonline.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;


import com.legoo.studaychineseonline.App;
import com.legoo.studaychineseonline.base.BaseActivity;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;



public class WXPayEntryActivity extends BaseActivity implements IWXAPIEventHandler {

    private IWXAPI iwxapi;

    @Override
    protected void myOnCreate(@Nullable Bundle savedInstanceState) {
       // iwxapi = WXAPIFactory.createWXAPI(this, API.WX_APP_ID);
        iwxapi.handleIntent(getIntent(), this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void resolveBundle(Bundle bundle) {

    }

    @Override
    protected int myLayoutId() {
        return 0;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        iwxapi.handleIntent(intent, this);

    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp baseResp) {

        if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

            if (baseResp.errCode == 0) {

                showToast("支付成功");

                finish();

            } else if (baseResp.errCode == -2) {
                showToast("支付取消");

                finish();
            } else {
                showToast("baseResp.errCode ="+baseResp.errCode);
                finish();
            }
        }
    }
}
